package com.ideal.frame.node.controller;

import com.ideal.frame.common.dto.ResponseModel;
import com.ideal.frame.node.dto.NodeSearchForm;
import com.ideal.frame.node.entity.RootNodeTb;
import com.ideal.frame.node.form.search.RootNodeSyncParams;
import com.ideal.frame.node.service.RootNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: liudingsheng
 * @Date: 2021/8/27
 * @Description:
 */
@Api(tags = "根节点管理")
@RestController
@RequestMapping("/rootnode")
public class RootNodeController {

    @Autowired
    private RootNodeService rootNodeService;

    @PostMapping("/sync/findBySyncTime")
    public ResponseModel findBySyncTime(@RequestBody RootNodeSyncParams params) {
        return ResponseModel.success(rootNodeService.findBySyncTime(params));
    }

    @ApiOperation(value = "同步根节点数据")
    @PostMapping("/sync/syncRootData")
    public ResponseModel syncRootData(@RequestBody List<RootNodeTb> list) {
        rootNodeService.syncRootData(list);
        return ResponseModel.success();
    }

    @GetMapping("getAllNotHasCerNodes")
    public ResponseModel getAllNotHasCerNodes() {
        return ResponseModel.success(rootNodeService.getAllNotHasCerNodes());
    }

    @PostMapping("/page")
    public ResponseModel page(@RequestBody NodeSearchForm form) {
        return ResponseModel.success(rootNodeService.getPage(form));
    }

    @GetMapping("/getById/{nodeId}")
    public ResponseModel getById(@PathVariable Long nodeId) {
        return ResponseModel.success(rootNodeService.getById(nodeId));
    }

    @PostMapping("/saveNode")
    public ResponseModel saveNode(@RequestBody RootNodeTb nodeTb) {
        rootNodeService.saveNode(nodeTb);
        return ResponseModel.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseModel delete(@PathVariable Long id) {
        rootNodeService.deleteNode(id);
        return ResponseModel.success();
    }

}
